package com.fuhao.route;

import com.fuhao.utils.RabbitUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 *  *                                          |-----C1
 *  *                           |----- Q1------|
 *  *                           |              |-----C2
 *                              |
 *  *     P-----Exange---bind---|
 *  *                           |              |-----C1
 *  *                           |----- Q2------|
 *  *                                          |-----C2
 *  bind绑定路由键
 *  Rabbit模型之路由模型
 * @author zhang
 */
public class Product {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitUtils.getConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare("exchange_direct","direct");

        String msg = "exchange direct queue";
        //direct类型需要绑定路由键，消费者完全匹配路由键才可以接收消息
        channel.basicPublish("exchange_direct","add",null,msg.getBytes());
        channel.close();
        connection.close();
    }
}
